
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
  
<script type="text/javascript" src="<%=jsPath%>/jquery/jquery.timers.js"></script><!--定时器-->
<script type="text/javascript" src="<%=jsPath%>/terminalCommand.js"></script><!--终端命令结果查询-->
</head>

		<script type="text/javascript" charset="utf-8">
		 var commandId = 0;
var mediaId = -1;
//当检索命令执行成功时
function onSearchSuccess(result)
{
    $("#btnQuery").click();

}

         function selectFile(_commandId, status)
         {
             commandId = _commandId;
             $("#btnPause").enable();
             $("#btnCancel").enable();
         }

function getRadioColumn(value, rowData, rowIndex)
{
    var commandId = rowData.commandId;
    var status = rowData.status;
    var html =   '<input type="radio" name="selectRadio" onclick="selectFile(' + commandId + ',\'' + status + '\');"    value="' + commandId + '" />';
    return html;

}

         function getDownloadActionColumn(alue, rowData, rowIndex)
         {
             var filePath = rowData.filePath;
             var status = rowData.status;
             var fileName = rowData.fileName;
             var html = status;
             if(status == "uploading")
                 html = "终端上传中";
             if(status == "upload_canceled")
                 html = "用户已取消";
             if(status == "upload_paused")
                 html = "用户已暂停";
             else if(status == "upload_completed" || status == "上传完成")
			 {
                 var url = "<%=ApplicationPath%>/videoDownload/downloadVideoFile.action?filePath=" + filePath;
                 html =  "<a href=\"javascript:window.open('" + url+ "');\">" + fileName +" </a>";

			 }
             return html;
         }



function controlUpload(controlCmd,cmdId)
{
    if(!cmdId)
        cmdId = commandId;
	if(cmdId <= 0)
	{
		$.messager.alert("提示","上传命令没有执行成功，不能暂停或取消");
		return;
	}

	if(controlCmd != 2)
	{
	    var btnName = $("#btnPause").val();
        controlCmd = btnName == "暂停" ? 0 :1;
            btnName = btnName == "暂停" ? "继续" : "暂停";
	    $("#btnPause").val(btnName);
	}
	var params = {commandId:cmdId,controlCmd:controlCmd,vehicleId:'${vehicleId}'};
	var url = "<%=ApplicationPath%>/videoDownload/controlUpload.action";
	$.getJSON(url, params, function(result)
	{
		if (result.success) {
			var commandId = result.data; //下发成功后，获取到命令Id
			if(controlCmd ==0 || controlCmd == 1)
			  TerminalCommand.commandButton = $("#btnPause");
			else
                TerminalCommand.commandButton = $("#btnCancel");

			TerminalCommand.startQueryResult(commandId,null, onSearchSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
		}else {
			$(".commandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
			//停止所有的在$('body')上定时器  
			$('body').stopTime ();  
	    }

	});
}

//填充报警标志下拉框
function initAlarmTypeList(alarmTypeList)
{
    $('#alarm').combotree({
        valueField: "alarmType", //Value字段
        textField: "name", //Text字段
        multiple: true,
        data: alarmTypeList,
        onCheck: function (node, checked) {
            //让全选不显示
            $("#alarm").combotree("setText", $("#alarm").combobox("getText").toString().replace("全选,", ""));
            var values = $('#alarm').combotree("getValues");
            var strAlarm = values.join(",");
            $("#alarmStatus").val(strAlarm);
        },
        onClick: function (node, checked) {
            //让全选不显示
            $("#alarm").combotree("setText", $("#alarm").combobox("getText").toString().replace("全选,", ""));
        }
    });

    $("#alarm").combotree("setText","不指定报警");
}

//下载任务执行条件下拉框
function initTaskCondition()
{
    $('#taskCombo').combotree({
        multiple: true,
        data: [{id:0,text:"WIFI下可下载"},{id:1,text:"有线连接时可下载"},{id:2,text:"无线3G/4G连接时可下载"}],
        onCheck: function (node, checked) {
            //让全选不显示
            $("#taskCombo").combotree("setText", $("#taskCombo").combobox("getText").toString().replace("全选,", ""));
            var values = $('#taskCombo').combotree("getValues");
            var taskCondition = values.join(",");
            $("#taskCondition").val(taskCondition);
        },
        onClick: function (node, checked) {
            //让全选不显示
            $("#taskCombo").combotree("setText", $("#taskCombo").combobox("getText").toString().replace("全选,", ""));
        }
    });

    //$("#taskCombo").combotree("setText","所有条件");
    $("#taskCombo",[0,1,2]).combotree('setValues',[0,1,2]);
    $("#taskCondition").val("0,1,2");

}

			$(document).ready(function() {
			    //获取报警列表
                var url = '<%=ApplicationPath%>/alarmConfig/terminalAlarmTypeList.action';
                $.getJSON(url, null, function(result)
                {
                    if(result.success)
                    {
                        initAlarmTypeList(result.data);
                    }
                });
                initTaskCondition();
                $("#channel").fillVehicleChannels({vehicleId:"${vehicleId}",selectedValue:"1"});

				 $("#entityForm").validate(); //初始化验证信息

				 var defaultRoleId = "";//${roleId}; //取出当前车辆的车牌颜色，默认选中
				//ajax填充下拉框数据 填充监听类型 选项
				 $("#eventType").lookup({category:"MediaEvent", selectedValue:1});
				 $("#videoDataType").lookup({category:"videoDataType", selectedValue:1});

				 var now = Utility.today();
				 var strDate = now + " 23:59:00";
				  $("#endDate").datetimebox('setValue', strDate);	
				  //var now = Utility.today();
				 strDate = (now + " 00:00:00");
				  $("#startDate").datetimebox('setValue', strDate);	

	             Utility.ajaxSubmitForm("entityForm", {
						 success:function(responseText)
						 {
							   var result = responseText;
								if (result.success) {
									 //alert("命令已经下发,请等待处理!");
									$("#btnPause").enable();
									 commandId = result.data; //下发成功后，获取到命令Id
			                         TerminalCommand.commandButton = $("#btnSearch");									 
                                     var url = null;//"<%=ApplicationPath%>/videoResourceSearch/getVideoResourceList.action";
									 TerminalCommand.startQueryResult(commandId,url,onSearchSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
								}
								else {
									$(".commandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
									//停止所有的在$('body')上定时器  
									$('body').stopTime ();  
								  }
						 }
				 });

                Utility.loadGridWithParams();
                $("#btnQuery").click(function(){
                    Utility.loadGridWithParams();
                });
			} );
		</script>
<body>
		<div id="toolbar" >		
			
		<form id="entityForm" name="entityForm" 
			action='<%=ApplicationPath%>/videoDownload/sendRequest.action' method="POST">
				
        <input type="hidden"  name="vehicleId"  id="queryVehicleId" value="${vehicleId}"/>
			<input type="hidden"  name="alarmStatus"  id="alarmStatus" value=""/>
			<input type="hidden"  name="taskCondition"  id="taskCondition" value="0,1,2"/>
  <table width="100%"  class="TableBlock">
					<tbody><tr>
						<td colspan="8" style="font-weight: bold; background: #EFEFEF;" height="25">音视频文件检索
						<span style="color:red;background:blue;">${message}</span>
						</td>
					</tr>
					<tr>
						<td align="right">通道
							:</td>
						<td>
							<select id="channel" name="channel" class="required">
							</select>
						</td>
						<td align="right">查询时间:</td>
						<td colspan="3">
							<input class="easyui-datetimebox" name="startDate" id="startDate" required style="width:160px" value=""></input>
							至
							<input class="easyui-datetimebox" name="endDate" id="endDate" required style="width:160px" value=""></input>
						</td>



					</tr>
					<tr>

						<td align="right">报警标志</td>
						<td>
							<select id="alarm" class="easyui-combotree" style="width: 200px; height: 24px;">
							</select>
						</td>

						<td align="right">音视频类型
							:</td>
						<td><select id="mediaType"  style="width: 150px;" name="mediaType">
							<option value="0" selected>音视频</option>
							<option value="1">音频</option>
							<option value="2">视频</option>
							<option value="3">视频或音视频</option>
						</select></td>




						<td align="right">码流类型:</td>
						<td colspan=1>
							<select name="streamType" id="streamType">
								<option value="0" selected>所有码流</option>
								<option value="1" >主码流</option>
								<option value="2">子码流</option>
							</select>
						</td>

					</tr>
					<tr>
						<td align="right">任务执行条件</td>
						<td>
							<select id="taskCombo" class="easyui-combotree" style="width: 200px; height: 24px;">
							</select>
						</td>
						<td align="right">存储器类型:</td>
						<td colspan=1>
							<select name="storeType" id="storeType">
								<option value="0" selected>所有</option>
								<option value="1">主存储器</option>
								<option value="2">备用存储器</option>
							</select>
						</td>
					</tr>
					<tr>
					  <td colspan=8>
					      <input type="submit" class="sendjson" id="btnSearch" value="上传到服务器">
						  &nbsp;&nbsp;
					      <input type="button"  id="btnPause" value="暂停" disabled onclick="controlUpload(0);">
						  &nbsp;&nbsp;
					      <input type="button" id="btnCancel"  value="取消" onclick="controlUpload(2);">
						  &nbsp;&nbsp;
						  <input type="button" value="查询文件上传状态"  title="查询" id="btnQuery"/>&nbsp;&nbsp;
						  <span class="commandMsg"></span> 
					  </td>

				</tbody></table>
				</form>

			<form id="queryForm" action="<%=ApplicationPath%>/report/paginate.action">
				<input type="hidden" name="queryId" value="videoFileItem.selectVideoFileItems" />
				<input type="hidden" name="fileSource" value="ftp" />
				<input type="hidden"  name="vehicleId"  id="vehicleId" value="${vehicleId}"/>
				<table width="100%"  class="TableBlock" style="display:none">
					<tr>
						<td> 围栏名称: </td>
						<td>			    <input type="text" name="name" size="10"  id="name">   </td>

						<td>
							绑定状态:
						</td>
						<td>
							<select id="bindState" name="bindState" >
								<option value=""> 所有</option>
								<option value="none"> 未绑定</option>
								<option value="success"> 已绑定</option>
							</select>
						</td>

						<td>
							<input type="reset" value="重置" title="重置"/>&nbsp;&nbsp;
						</td>
					</tr>
				</table>

			</form>

			</div>

		<table id="queryGrid" class="easyui-datagrid"
			   data-options="pagination:true,pageSize:15,singleSelect:true,rownumbers:true,striped:true,fitColumns: true,
						pageList: [15, 20, 50, 100, 150, 200],fit:true,toolbar:'#toolbar',checkOnSelect: false, selectOnCheck: false,
						url:'<%=ApplicationPath%>/report/paginate.action',method:'get'">
					<thead>
						<tr>
							<th data-options="field:'commandId',formatter:getRadioColumn" width="4%">选择</th>
							<th data-options="field:'channelId'" width="5%">通道</th>
							<th data-options="field:'startDate'" width="16%">开始时间</th>
							<th data-options="field:'endDate'" width="16%">结束时间</th>
							<th data-options="field:'alarmStateDescr'" width="8%">报警标志</th>
							<th data-options="field:'dataType'" width="8%">资源类型</th>
							<th data-options="field:'streamType'" width="8%">码流类型</th>
							<th data-options="field:'storeType'" width="6%">存储器</th>
							<th data-options="field:'filePath',formatter:getDownloadActionColumn" width="50%">下载</th>
							<th data-options="field:'createDate'" width="16%">创建时间</th>
						</tr>
					</thead>
					<tbody>
						
					</tbody>					
				</table>
</body>

